const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n;
let initArr = [];
//5
//1 0 100
//2 0 199
//3 0 200
//4 0 200
//5 0 200
rl.on("line", (line) => {
    if (n === undefined) {
        n = Number(line.trim())
    } else {
        initArr.push(line.trim().split(/\s+/).map(Number))
        if (initArr.length === n) {
            console.log(getResult(n, initArr))

            // clear
            n = undefined
            initArr.length = 0
            //rl.close()
        }
    }

})

class node {
    constructor(plus, deep) {
        this.plus = plus
        this.deep = deep
    }
}

function getResult(n, initArr) {
    // 先构建邻接表
    let map = {}
    for (const [a, b, c] of initArr) {
        // 父元素
        if (!map[b]) {
            map[b] = {
                id: b,
                child: [a],
                deep: 0,
                value: 0,
                plus: 0
            }
        } else {
            map[b].child.push(a)
        }
        // 子元素
        map[a] = {
            id: a,
            child: map[a]?.child || [], // 细节
            deep: 0,
            value: c,
            plus: 0
        }
    }

    // 再逐个遍历, 拿到deep, plus
    //再找最大deep
    let deepMax = 0
    let keyMax = 0
    for (const key of Object.keys(map)) {
        let node = dfs(key, map)
        if (node.deep > deepMax) {
            deepMax = Math.max(deepMax, node.deep)
            keyMax = key
        }
    }
    return `${keyMax} ${map[keyMax].value + map[keyMax].plus}`
}

// 要传递给上级的是抽成, 和deep {deep, plus}
function dfs(key, map) {
    let obj = map[key]
    // 缓存
    if (obj.plus !== 0) {
        return new node(Math.floor((obj.value  + obj.plus)/ 100) * 15, obj.deep)
    }

    let plus = 0
    let deep = 0
    if (obj.child.length) { // 有孩子
        let child = obj.child
        for (const id of child) {
            let node = dfs(id, map)
            plus += node.plus
            deep = Math.max(deep, node.deep)
        }
        obj.plus = plus
        obj.deep = deep + 1
    }
    plus = Math.floor((obj.value  + obj.plus)/ 100) * 15
    return new node(plus, obj.deep)
}